import * as types from "../../../config/postMessage-types";
import store from "../../../store";
import zx from './zx';
import gw from "./gw";
import ly from './ly'
import {qxzWebviewActiveFn} from "./qxz";//处理webview重新激活的事件
import {gwWebviewActiveFn} from "./gw";//处理webview重新激活的事件
export default () => {
    return {
        [types.GO_BACK]: () => {
            console.log("判断是否需要退出webview", store.getters["gw/getExitWebviewState"]);
            store.dispatch('qxz/updateBackTrigger');
            let exitWebviewState = store.getters["gw/getExitWebviewState"];
            if (exitWebviewState) {
                let msg = JSON.stringify({
                    type: types.EXIT_WEBVIEW,
                });
                window.postMessage(msg);
            } else {
                window.history.go(-1);
            }
        },
        [types.TEST]: (result) => {
            console.log("接收到", result);
        },
        [types.WEBVIEW_ACTIVE]: (result) => {
            let params = result.params;
            // console.log("WEBVIEW_ACTIVE", params);
            //用户信息更新到vuex中
            params.userInfo && store.commit("wxh/USER_INFO", params.userInfo);
            params.sessionId && store.commit("wxh/RECORD_SESSIONID", params.sessionId);
            //sessionId添加到localStorage中
            params.sessionId && localStorage.setItem('sessionId',params.sessionId);
            gwWebviewActiveFn(result);
            qxzWebviewActiveFn(params);
        },
        ...zx,
        ...gw,
        ...ly
    }
}